package com.kitty.web.controller;

import com.kitty.common.cache.RedisService;
import com.kitty.web.controller.BaseController;
import com.kitty.web.common.AjaxResult;
import com.kitty.web.core.page.TableDataInfo;
import com.kitty.web.domain.Rediscache;
import com.kitty.web.system.rediscache.service.IRediscacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 充值排行榜Controller
 * 
 * @author soul
 * @date 2022-03-15
 */
@Controller
@RequestMapping("/system/rediscache")
public class RediscacheController extends BaseController
{
    @Autowired
    RedisService redisService;
    private String prefix = "system/rediscache";

    @Autowired
    private IRediscacheService rediscacheService;



    @GetMapping()
    public String rediscache()
    {
        return prefix + "/rediscache";
    }

    /**
     * 查询充值排行榜列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Rediscache rediscache)
    {

        startPage();
        List<Rediscache> list = rediscacheService.selectRediscacheList(rediscache);
        return getDataTable(list);
    }

    /**
     * 新增充值排行榜
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存充值排行榜
     */

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Rediscache rediscache)
    {
        return toAjax(rediscacheService.insertRediscache(rediscache));
    }

    /**
     * 修改充值排行榜
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {

        Rediscache rediscache = rediscacheService.selectRediscacheById(id);
        mmap.put("rediscache", rediscache);
        return prefix + "/edit";
    }

    /**
     * 修改保存充值排行榜
     */

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Rediscache rediscache)
    {
//        redisService.set("recharge_date_count_start",rediscache.getStarttime());
//        redisService.set("recharge_date_count_end",rediscache.getEndtime());
//        redisService.set("recharge_item",rediscache.getItem());
//        redisService.set("recharge_prize",rediscache.getPrize());
//        redisService.set("recharge_prize_state",rediscache.getState());
        return toAjax(rediscacheService.updateRediscache(rediscache));
    }

    /**
     * 删除充值排行榜
     */

    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rediscacheService.deleteRediscacheByIds(ids));
    }
}
